﻿@page "/hwscan"
@inject Services.HuaweiScanService huaweiScanService;

<h3>华为统一扫码服务在MAUI BLAZOR应用中的演示</h3>
<p>扫码结果:@ScanResult</p>
<button @onclick="OnScanBtnClick">扫一扫</button>
@code {
    private string ScanResult { get; set; } = string.Empty;
    protected override void OnInitialized()
    {
        base.OnInitialized();

    }
    private async Task OnScanBtnClick() 
    {

        try
        {
            await huaweiScanService.StartScan(
                EventCallback.Factory.Create<string>(this, HandleScan)
            );
        }
        catch (Exception ex)
        {
            ScanResult = $"扫码失败: {ex.Message}";
        }
    }


    private Task HandleScan(string result)
    {
        ScanResult = result;
        return Task.CompletedTask;
    }
}
